home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_a / entrys.act < prev    next >
Text File  |  1995-04-22  |  11KB  |  509 lines

  1. ;************************************
  2. ;*                                  *
  3. ;*(C)Copyright 1986 by Paul B. Loux *
  4. ;*                                  *
  5. ;* These routines are in the public *
  6. ;* domain,  and  are not to be sold *
  7. ;* for a profit. They may be freely *
  8. ;* distributed, provided  that this *
  9. ;* header remains in place. Use and *
  10. ;* enjoy! PBL, CIS 72337,2073.      *
  11. ;*                                  *
  12. ;************************************
  13. ;*                                  *
  14. ;*  File "ENTRYS.LIB"               *
  15. ;*                                  *
  16. ;*  Description: Universal string   *
  17. ;*    input routine, offering full  *
  18. ;*    control over keyboard input   *
  19. ;*    and screen display.  Allows   *
  20. ;*    program to limit responses    *
  21. ;*    to acceptable parameters.     *
  22. ;*                                  *
  23. ;*  Calling parameters:             *
  24. ;*                                  *
  25. ;*    FIELD   The field buffer.     *
  26. ;*                                  *
  27. ;*    MIN     Minimum number of     *
  28. ;*            characters for        *
  29. ;*            valid response, 0-MAX.*
  30. ;*                                  *
  31. ;*    MAX     Maximum number of     *
  32. ;*            characters, 1-36.     *
  33. ;*                                  *
  34. ;*    TYPEC   Type Code:            *
  35. ;*            1 Alphanumeric        *
  36. ;*            2 Force Upper Case    *
  37. ;*            3 Signed integer      *
  38. ;*            4 Signed real (float) *
  39. ;*            5 Unsigned integer    *
  40. ;*            6 Unsigned real       *
  41. ;*            7 Yes/No check        *
  42. ;*            (Note: no range check *
  43. ;*            is provided on the    *
  44. ;*            numeric response)     *
  45. ;*                                  *
  46. ;*    XIT     Exit record if the    *
  47. ;*            first character in    *
  48. ;*            FIELD is ESC.         *
  49. ;*                                  *
  50. ;*    COL     Screen display        *
  51. ;*            horizontal position   *
  52. ;*            for input echo, 2-37. *
  53. ;*                                  *
  54. ;*    ROW     Screen display        *
  55. ;*            vertical position     *
  56. ;*            for input echo, 1-22. *
  57. ;*                                  *
  58. ;*    ERRPTR  Pointer variable to   *
  59. ;*            pass error code on    *
  60. ;*            record aborts (Ctrl-Z)*
  61. ;*            or XIT's (above).     *
  62. ;*                                  *
  63. ;*    Note:   User entry of ESC will*
  64. ;*            restart field entry,  *
  65. ;*            or exit (see above).  *
  66. ;*            Entry of Ctrl-Z aborts*
  67. ;*            record. The routine   *
  68. ;*            uses the BYTE FUNC    *
  69. ;*            Fetch() to obtain the *
  70. ;*            keystokes, allowing   *
  71. ;*            timeout control.      *
  72. ;*                                  *
  73. ;************************************
  74. ;
  75. ;   Atari OS Variables for sound
  76. ;   control and PROC Sound_reset.
  77. ;
  78. MODULE
  79.  
  80. BYTE AudCtl=$D208, SKCtl=$D20F,
  81.      AudC1 =$D201, AudC2=$D203,
  82.      AudC3 =$D205, AudC4=$D207
  83.  
  84. PROC Sound_reset()
  85.  
  86.  
  87. AudCtl=0 SKCtl=3
  88. AudC1 =0 AudC2=0 AudC3=0 AudC4=0
  89.  
  90. RETURN
  91. ;
  92. ;************************************
  93. ;
  94. ;   BYTE FUNC FetchD
  95. ;     (BYTE ioch,Time_out)
  96. ;               
  97. ;   This function is an enhancement
  98. ;   to the library  routine GetD().
  99. ;   Basically it is a GetD() with a
  100. ;   timeout spec.  The routine uses
  101. ;   the Atari System Timer 4, whose
  102. ;   counter is located at $21E,$21F
  103. ;   and  whose zero-flag is located
  104. ;   at $22C. Normally, the function
  105. ;   RETURNs the  same ATASCII  code
  106. ;   that a  GetD() would.  However,
  107. ;   if no key is pressed  prior  to
  108. ;   time-out, the function RETURNs
  109. ;   an ATASCII value of 255. Should
  110. ;   a user actually try to  enter a
  111. ;   character-255, the key sequence
  112. ;   is ignored.
  113. ;
  114. ;   Through use of the  OS variable 
  115. ;   POKMSK, FetchD()  disables  the
  116. ;   Break key upon each call.
  117. ;
  118. ;   The value in the  BYTE Time_Out
  119. ;   represents  the  time limit  in
  120. ;   seconds. A value of zero  means
  121. ;   that there  is  no time  limit. 
  122. ;   The maximum value for Time_out,
  123. ;   255,  represents 4 minutes  and
  124. ;   fifteen seconds.  If  more time
  125. ;   is required,  try using a short
  126. ;   Time_out but use a loop to make
  127. ;   the call to FetchD(), or modify
  128. ;   the routine to use a CARD.
  129. ;
  130. ;   The  BYTE ioch  represents  the
  131. ;   IOCB  channel from  which input 
  132. ;   is to be obtained. The  routine
  133. ;   assumes the channel has already
  134. ;   been opened for input from K:. 
  135. ;   
  136. ;
  137.  
  138. BYTE FUNC FetchD(BYTE ioch,Time_Out)
  139.  
  140. BYTE POKMSK=$10       ; IRQ nabl bits
  141. CARD CDTMV3=$21E      ; timer 4 value
  142. BYTE CDTMF3=$22C      ; timer 4 flag
  143. BYTE CH=$2FC          ; key pressed
  144. BYTE IRQEN=$D20E      ; Pokey IRQ
  145.  
  146. CARD jiffies
  147. BYTE response
  148.  
  149. POKMSK==&127          ; disable Break
  150. IRQEN==&127           
  151.  
  152. jiffies=Time_Out*60
  153. CH=255
  154. CDTMF3=255
  155. CDTMV3=jiffies
  156.  
  157. DO
  158.  IF CH#255 THEN
  159.   response=GETD(ioch)
  160.   IF response#255 THEN
  161.    RETURN(response)
  162.   FI
  163.  FI
  164. UNTIL CDTMF3=0
  165. OD
  166.  
  167. ;POKMSK==%128         ; uncomment to
  168. ;IRQEN==%128          ; restore BRKKEY
  169.  
  170. RETURN(255)
  171. ;
  172. ;************************************
  173. ;
  174. ;   This routine places a message
  175. ;   at the bottom  of the screen.
  176. ;
  177.  
  178. PROC MSG(BYTE code)
  179.  
  180. BYTE ARRAY mesag
  181. CARD ARRAY index(10)
  182. CARD ctr
  183.  
  184. BYTE ROWCRS=$54,row
  185. CARD COLCRS=$55,col
  186.  
  187. index(0)="                                   "
  188. index(1)="Too short-- continue"
  189. index(2)="Too long-- press RETURN or Edit"
  190. index(3)="Record aborted-- press ESC to clear"
  191. index(4)="Numeric input only-- continue"
  192. index(5)="Positive numbers only-- continue"
  193. index(6)="Integers only-- continue"
  194. index(7)="Value out of range-- press ESC"      
  195. index(8)="Invalid date-- press ESC"
  196. index(9)="PROGRAM ERROR-- press ESC to bypass"
  197.  
  198.  
  199. IF code>9 THEN code=9 FI
  200. mesag=index(code)
  201.  
  202. IF code>0 THEN Sound_reset()
  203.                SOUND(0,20,10,10)
  204.                FOR ctr=1 TO 2000
  205.                  DO
  206.                   ;
  207.                  OD
  208.                Sound_reset()
  209. FI
  210.  
  211. row=ROWCRS
  212. col=COLCRS
  213.  
  214. POSITION(1,23)
  215. PUT(156)       ; delete line
  216. PRINT(mesag)
  217.  
  218. IF code=9 THEN
  219.   PUT(253)
  220. FI
  221.  
  222. IF code=3 OR code=7 OR
  223.    code=8 OR code=9 THEN
  224.   DO
  225.    ctr=FETCHD(7,10)       ; 10 second
  226.   UNTIL ctr=27 OR ctr=255 ; timeout
  227.   OD
  228. FI
  229.  
  230. COLCRS=col+1
  231. ROWCRS=row
  232. PUT(30)
  233.  
  234. RETURN
  235.  
  236. ;************************************
  237. ;
  238. ;  This is the actual Entry routine.
  239. ;
  240.  
  241. PROC ENTRYS (BYTE ARRAY field
  242.              BYTE min,max,typec,xit,
  243.              col,row
  244.              BYTE POINTER errptr)
  245.  
  246. BYTE dotflg,code,ctr,chr,intrpt,accept
  247.  
  248. BYTE ROWCRS=$54
  249. CARD COLCRS=$55
  250.  
  251. DEFINE FILLCHR="46"     ; "."
  252.  
  253. BYTE INVFLG=$2B6
  254. BYTE SHFLOK=$2BE
  255. BYTE SHFTMP
  256.  
  257. IF col+max> 38 OR row>22 OR col<2
  258.   OR max<min OR max<1 THEN
  259.   MSG(9)
  260.   RETURN
  261. FI
  262.  
  263. SHFTMP=SHFLOK
  264. SHFLOK=0
  265. INVFLG=0
  266. dotflg=0
  267.  
  268. MSG(0)
  269.          
  270. COLCRS=col
  271. ROWCRS=row
  272. FOR ctr=1 TO max DO PUT(FILLCHR)
  273.                     field(ctr)=32
  274.                  OD
  275. field(0)=max            ; needed?
  276. col==+1
  277. ctr=0
  278.  
  279. DO
  280.     accept=0
  281.     intrpt=0
  282.     COLCRS=col+ctr
  283.     ROWCRS=row
  284.     PUT(30)
  285.     ctr==+1
  286.  
  287.  DO
  288.     chr=FETCHD(7,30)    ; 30 second
  289.                         ; timeout
  290.  
  291.     IF chr=255 THEN     ; timeout
  292.          errptr^=3
  293.          intrpt=1
  294.          EXIT
  295.  
  296.     ELSEIF chr=155 THEN ; RETURN
  297.          IF ctr<=min THEN
  298.               MSG(1)
  299.          ELSE intrpt=1
  300.               EXIT
  301.          FI
  302.  
  303.     ELSEIF chr=126 THEN ; BS
  304.          IF ctr>1 THEN
  305.            ctr==-1
  306.            IF (typec=5 OR typec=6) 
  307.             AND field(ctr)=46
  308.             THEN dotflg=0
  309.            FI
  310.            field(ctr)=32
  311.            PUT(30)
  312.            PUT(FILLCHR)
  313.            PUT(30)
  314.            MSG(0)
  315.          FI
  316.  
  317.     ELSEIF chr=26 THEN  ; Ctrl-Z
  318.          FOR ctr=1 TO max
  319.           DO
  320.            field(ctr)=32
  321.           OD
  322.          ctr=0
  323.          MSG(3)
  324.          errptr^=2
  325.          intrpt=1
  326.          EXIT
  327.  
  328.     ELSEIF chr=27 THEN  ; ESC
  329.          IF ctr>1 THEN
  330.           COLCRS=col-1
  331.           ROWCRS=row
  332.           FOR ctr=1 TO max
  333.            DO
  334.             PUT(FILLCHR)
  335.             field(ctr)=32
  336.            OD
  337.           ctr=1
  338.           dotflg=0
  339.           COLCRS=col
  340.           ROWCRS=row
  341.           PUT(30)
  342.          ELSE
  343.           IF xit=1 THEN
  344.            errptr^=1
  345.            intrpt=1
  346.            EXIT
  347.           FI
  348.          FI
  349.  
  350.     ELSEIF ctr>max THEN
  351.          MSG(2)
  352.  
  353.     ELSEIF (chr<32
  354.          OR chr>122
  355.          OR chr=96)     ; Goofy Keys
  356.          THEN SH